package com.aaa.controller;

import com.aaa.common.domain.Dept;
import com.aaa.common.query.DeptQuery;
import com.aaa.common.result.Result;
import com.aaa.service.impl.DeptServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeptServiceImpl service;

    /**
     * 查询部门
     */
    @PostMapping("/listP")
    public Result listPersonRenter(@RequestBody DeptQuery deptQuery){
        Result result = service.listDept(deptQuery);
        System.out.println(result);
        return result;
    }

    /**
     * 添加部门
     * @return
     */
    @PostMapping("/add")
    public Result addPersonRenter(@RequestBody Dept dept){
        Result result = service.addDept(dept);
        return result;
    }

    /**
     * 修改部门
     * @return
     */
    @PostMapping("/update")
    public Result updatePersonRenter(@RequestBody Dept dept){
        boolean b = service.updateDept(dept);
        if (b==true){
            return Result.success(b);
        }
        return Result.error("error");
    }

    /**
     * 通过id查询该数据
     * @param id
     * @return
     */
    @GetMapping("getId")
    public Result getId(Integer id){
        Result result = service.listUserById(id);
        return result;
    }

    /**
     * 删除部门
     * @return
     */
    @DeleteMapping("/delete")
    public Result delPersonRenter(String ids){
        return service.delByIds(ids);

    }
}
